/*
 * TakingMoveFrame.java
 * Team qq 2011
 */
package com.google.code.timetrail.gui;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.google.code.timetrail.backend.*;

import java.awt.AlphaComposite;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Rectangle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import java.awt.Component;
import javax.swing.JSeparator;

public class TakingMoveFrame extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private TakingMoveFrameBackend takingMoveFrameBackend;
	
	/**
	 * Create the panel.
	 */
	private Control myGameControl;
	private JPanel myCD;
	private JLabel foodStatusLabel;
	private JLabel distanceStatusLabel;
	private JLabel rationsStatusLabel;
	private JLabel paceStatusLabel;
	private JLabel currentLocationStatusLabel;

	private JLabel turnStatusLabel;
	private String myPrevious;
	private mapPanel panel;
	private BufferedImage background;
	private JButton changePaceRationsButton;
	private JButton takeTurnButton;
	private mapPanel mapPanel;

	
	public TakingMoveFrame(Control gameControl, JPanel cd, String previous) {
		//setBounds(new Rectangle(0, 0, 600, 200));
		this.myGameControl = gameControl;
		this.myCD = cd;
		this.myPrevious = previous;
		
		takingMoveFrameBackend = new TakingMoveFrameBackend(myGameControl);
		
		turnStatusLabel = new JLabel(takingMoveFrameBackend.getTurnLabelText());
		
		foodStatusLabel = new JLabel(takingMoveFrameBackend.getFoodLabelText());
		
		distanceStatusLabel = new JLabel(takingMoveFrameBackend.getDistanceLabelText());
		
		rationsStatusLabel = new JLabel(takingMoveFrameBackend.getRationsLabelText());
		
		paceStatusLabel = new JLabel(takingMoveFrameBackend.getPaceLabelText());
		
		currentLocationStatusLabel = new JLabel(takingMoveFrameBackend.getCurrentLocText());
		
		changePaceRationsButton = new JButton(takingMoveFrameBackend.getPaceRationsButtonText());
		changePaceRationsButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				myCD.add(new RationsPaceFrame(myGameControl, myCD, "TakeMove"), "name_1317840867491837002");
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.next(myCD);
			}
		});
		
	
	    
		//panel = new mapPanel("background2.gif","spaceship.jpg",gameControl);
		//panel.setBounds(0, 0, this.getSize().width, this.getSize().height);
	    //panel.setBorder(BorderFactory.createLineBorder (Color.black, 2));
		//add(panel);
		
		takeTurnButton = new JButton(takingMoveFrameBackend.getContinueButtonText());
		takeTurnButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(myGameControl.getCurrentPlace().equals(Place.OREGON)){
					takeTurnButton.setEnabled(false);
				}
				takingMoveFrameBackend.pressContinue();
				foodStatusLabel.setText(takingMoveFrameBackend.getFoodLabelText());
				distanceStatusLabel.setText(takingMoveFrameBackend.getDistanceLabelText());
				turnStatusLabel.setText(takingMoveFrameBackend.getTurnLabelText());
				currentLocationStatusLabel.setText(takingMoveFrameBackend.getCurrentLocText());
				mapPanel.repaint();
			}
		});
		
		mapPanel = new mapPanel("background2.gif","spaceship.jpg",gameControl);
	    mapPanel.setBorder(BorderFactory.createLineBorder (Color.black, 1));
		
		
		JSeparator separator = new JSeparator();
		

		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(68)
					.addComponent(takeTurnButton, GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
					.addGap(117)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(changePaceRationsButton, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
						.addComponent(turnStatusLabel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
						.addComponent(foodStatusLabel, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
						.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
							.addComponent(currentLocationStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(paceStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(rationsStatusLabel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(distanceStatusLabel, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
					.addGap(93))
				.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(mapPanel, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
					.addContainerGap())
				.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(separator, GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(mapPanel, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(8)
							.addComponent(turnStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addGap(11)
							.addComponent(foodStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addGap(11)
							.addComponent(distanceStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addGap(11)
							.addComponent(rationsStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
							.addComponent(paceStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addGap(11)
							.addComponent(currentLocationStatusLabel, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(changePaceRationsButton, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
							.addGap(16))
						.addGroup(groupLayout.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
							.addComponent(takeTurnButton, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
							.addGap(102))))
		);
		groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {turnStatusLabel, foodStatusLabel, distanceStatusLabel, rationsStatusLabel, paceStatusLabel, currentLocationStatusLabel, changePaceRationsButton});
        setLayout(groupLayout);
	}
}
